#include<bits/stdc++.h>
#define N 100000
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std ;

inline int read(){
	int s=0,w=1;char c=getchar();
	while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}
	while(c>=48&&c<=57) s=(s<<1)+(s<<3)+c-48,c=getchar();
	return s*w;
}

int n;
ll f[N+100],ans=inf;
struct node{int x,y;}a[N+100];
bool cmp(node x,node y){return x.y<y.y;}

int main(){

	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);

	n=read();
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	sort(a+1,a+n+1,cmp);
	
	int pos1=0,pos2=0;
	a[0].x=inf,f[0]=inf;
	for(int i=1;i<=n;i++){
		f[i]=a[pos1].x+a[i].y+a[i].x,
		ans=min(ans,f[pos2]+a[i].y+a[i].x);
		if(a[i].x<a[pos1].x) pos1=i;
		if(f[i]<f[pos2]) pos2=i;
	}
	
	printf("%lld",ans);
	return 0;
}


